package com.battery.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.battery.common.annotation.Log;
import com.battery.common.enums.BusinessType;
import com.battery.system.domain.VersionApp;
import com.battery.system.service.IVersionAppService;
import com.battery.common.core.controller.BaseController;
import com.battery.common.core.domain.AjaxResult;
import com.battery.common.utils.poi.ExcelUtil;
import com.battery.common.core.page.TableDataInfo;

/**
 * 免电APP版本管理Controller
 * 
 * @author battery
 * @date 2021-03-16
 */
@Controller
@RequestMapping("/system/app")
public class VersionAppController extends BaseController
{
    private String prefix = "system/app";

    @Autowired
    private IVersionAppService versionAppService;

    @RequiresPermissions("system:app:view")
    @GetMapping()
    public String app()
    {
        return prefix + "/app";
    }

    /**
     * 查询免电APP版本管理列表
     */
    @RequiresPermissions("system:app:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VersionApp versionApp)
    {
        startPage();
        List<VersionApp> list = versionAppService.selectVersionAppList(versionApp);
        return getDataTable(list);
    }

    /**
     * 导出免电APP版本管理列表
     */
    @RequiresPermissions("system:app:export")
    @Log(title = "免电APP版本管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VersionApp versionApp)
    {
        List<VersionApp> list = versionAppService.selectVersionAppList(versionApp);
        ExcelUtil<VersionApp> util = new ExcelUtil<VersionApp>(VersionApp.class);
        return util.exportExcel(list, "app");
    }

    /**
     * 新增免电APP版本管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存免电APP版本管理
     */
    @RequiresPermissions("system:app:add")
    @Log(title = "免电APP版本管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VersionApp versionApp)
    {
        return toAjax(versionAppService.insertVersionApp(versionApp));
    }

    /**
     * 修改免电APP版本管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        VersionApp versionApp = versionAppService.selectVersionAppById(id);
        mmap.put("versionApp", versionApp);
        return prefix + "/edit";
    }

    /**
     * 修改保存免电APP版本管理
     */
    @RequiresPermissions("system:app:edit")
    @Log(title = "免电APP版本管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VersionApp versionApp)
    {
        return toAjax(versionAppService.updateVersionApp(versionApp));
    }

    /**
     * 删除免电APP版本管理
     */
    @RequiresPermissions("system:app:remove")
    @Log(title = "免电APP版本管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(versionAppService.deleteVersionAppByIds(ids));
    }
}
